import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home/index",
  },
  {
    path: "/home",
    name: "home",
    component: HomeView,
    redirect: "/home/index", //重定向
    // 路由嵌套
    children: [
      {
        path: "index",
        name: "首页",
        component: () => import("../views/Index.vue"),
      },
      {
        path: "me",
        name: "我的",
        component: () => import("../views/Me.vue"),
      },
    ],
  },
  {
    path: "/about",
    name: "about",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: "/register",
    name: "注册",
    component: () => import("../views/Register.vue"),
  },
  {
    path: "/login",
    name: "登录",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/field",
    name: "测试表单页面",
    component: () => import("../views/testing/Field.vue"),
  },
  {
    path: "/nav",
    name: "测试导航",
    component: () => import("../views/testing/Nav.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
